import {
  setUserPhone
} from '../../../api/user';
Page({
  data: {
    nameValue: '',
    phoneError: false,
  },
  onLoad(options) {
    const {
      phone
    } = options;
    const {
      phoneError
    } = this.data;
    const isPhoneNumber = /^[1][3,4,5,7,8,9][0-9]{9}$/.test(phone);
    if (phoneError === isPhoneNumber) {
      this.setData({
        phoneError: !isPhoneNumber,
      });
    }

    this.setData({
      nameValue: phone,
    });
  },
  onPhoneInput(e) {
    const {
      phoneError
    } = this.data;
    const isPhoneNumber = /^[1][3,4,5,7,8,9][0-9]{9}$/.test(e.detail.value);
    if (phoneError === isPhoneNumber) {
      this.setData({
        phoneError: !isPhoneNumber,
      });
    }
  },
  onSubmit() {
    setUserPhone({
      "phone": this.data.nameValue
    }).then(res => {
      wx.navigateBack({
        backRefresh: false
      });
    })

  },
  clearContent() {
    this.setData({
      nameValue: '',
    });
  },
});